import type {
  FormDefinitionForm,
  FormDefinitionQuery,
  FormDefinitionVO,
} from './model';

import type { ID, IDS, PageResult } from '#/api/common';

import { commonExport } from '#/api/helper';
import { requestClient } from '#/api/request';

/**
 * 查询动态表单列表
 * @param params
 * @returns 动态表单列表
 */
export function formDefinitionList(params?: FormDefinitionQuery) {
  return requestClient.get<PageResult<FormDefinitionVO>>(
    '/workflow/formDefinition/list',
    { params },
  );
}

/**
 * 导出动态表单列表
 * @param params
 * @returns 动态表单列表
 */
export function formDefinitionExport(params?: FormDefinitionQuery) {
  return commonExport('/workflow/formDefinition/export', params ?? {});
}

/**
 * 查询动态表单详情
 * @param formId id
 * @returns 动态表单详情
 */
export function formDefinitionInfo(formId: ID) {
  return requestClient.get<FormDefinitionVO>(
    `/workflow/formDefinition/${formId}`,
  );
}

/**
 * 新增动态表单
 * @param data
 * @returns void
 */
export function formDefinitionAdd(data: FormDefinitionForm) {
  return requestClient.postWithMsg<void>('/workflow/formDefinition', data);
}

/**
 * 更新动态表单
 * @param data
 * @returns void
 */
export function formDefinitionUpdate(data: FormDefinitionForm) {
  return requestClient.putWithMsg<void>('/workflow/formDefinition', data);
}

/**
 * 发布动态表单
 * @param formId id
 * @returns void
 */
export function formDefinitionPublish(formId: ID) {
  return requestClient.putWithMsg<void>(
    `/workflow/formDefinition/publish/${formId}`,
  );
}

/**
 * 删除动态表单
 * @param formId id
 * @returns void
 */
export function formDefinitionRemove(formId: ID | IDS) {
  return requestClient.deleteWithMsg<void>(
    `/workflow/formDefinition/${formId}`,
  );
}
